<template>
  <div>
    <van-nav-bar title="账号登录" left-arrow @click-left="fn" />
    <van-form validate-first @submit="sub">
      <!-- 通过 pattern 进行正则校验 -->
      <van-field
        v-model="obj.username"
        name="pattern"
        placeholder="请输入账号"
        :rules="[{ pattern, message: '请输入5-8位字母和数字账号' }]"
      />
      <!-- 通过 pattern 进行正则校验 -->
      <van-field
        v-model="obj.password"
        name="pattern"
        placeholder="请输入密码"
        type="password"
        :rules="[{ pattern, message: '请输入5-8位字母和数字密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >登录</van-button
        >
      </div>
    </van-form>
    <span @click="$router.push('/registe')">还没有账号,去注册~</span>
  </div>
</template>

<script>
import { setToken } from '@/utils/storage'
import { dl } from '@/api/article'
export default {
  name: 'MyLogn',
  components: {},
  props: {},
  data() {
    return {
      obj: {
        username: '',
        password: ''
      },
      pattern: /^[A-Za-z0-9]{5,8}$/
    }
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    async sub() {
      const res = await dl(this.obj)
      console.log(res)
      setToken(res.body.token)
      this.$toast('登录成功')
      this.$router.push('/mymy')
    },
    fn() {
      this.$router.back()
    }
  }
}
</script>

<style scoped lang="less">
span {
  margin-left: 20px;
  font-size: 14px;
}
::v-deep.van-nav-bar .van-icon {
  color: white;
}
::v-deep .van-nav-bar {
  background-color: #21b97a;
}
::v-deep .van-nav-bar__title {
  color: white;
  font-weight: 500;
  font-size: 18px;
}
::v-deep .van-button {
  background-color: #21b97a;
  border: 1px solid #21b97a;
}
.van-button--round {
  border-radius: 2px;
}
.van-cell {
  height: 75px;
}
::v-deep .van-field__control {
  margin-top: 20px;
}
</style>
